<#--noinspection ALL-->
<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
    <#if hasQuery>
      <div v-if="crud.props.searchToggle || !isOpenInMain ">
        <!-- 搜索 -->
        <#if queryColumns??>
          <#list queryColumns as column>
            <#if column.queryType != 'BetWeen'>
         <span>
        <label class="el-form-item-label"><#if column.remark != ''>${column.remark}<#else>${column.changeColumnName}</#if></label>
      <!--  <el-input v-model="query.${column.changeColumnName}" clearable placeholder="<#if column.remark != ''>${column.remark}<#else>${column.changeColumnName}</#if>" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />-->
        <autocompleteinput v-model="query.${column.changeColumnName}" type="text"  :bussinessurl="bussinessurl" columnname="${column.changeColumnName}" :queries="query"  @autocompleted="crud.toQuery" clearable placeholder="<#if column.remark != ''>${column.remark}<#else>${column.changeColumnName}</#if>" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery"/>
         </span>
            </#if>
          </#list>
        </#if>
  <#if betweens??>
    <#list betweens as column>
      <#if column.queryType = 'BetWeen'>
        <date-range-picker
          v-model="query.${column.changeColumnName}"
          start-placeholder="${column.changeColumnName}Start"
          end-placeholder="${column.changeColumnName}Start"
          class="date-item"
        />
      </#if>
    </#list>
  </#if>
        <rrOperation />
      </div>
    </#if>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation v-if="isOpenInMain" :permission="permission" :hiddenColumns="hiddenColumns" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" :width="dialogWidth">
        <addform  size="small" labelwidth="80px" @fitWidth="(val)=>{dialogWidth=val}"/>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <#if columns??>
          <#list columns as column>
            <#if column.columnShow>
              <#if (column.dictName)?? && (column.dictName)!="">
                <el-table-column prop="${column.changeColumnName}" label="<#if column.remark != ''>${column.remark}<#else>${column.changeColumnName}</#if>">
                  <template slot-scope="scope">
                    {{ dict.label.${column.dictName}[scope.row.${column.changeColumnName}] }}
                  </template>
                </el-table-column>
                <!--  显示图片  -->
              <#elseif column.formType = 'Picture'>
                <el-table-column prop="${column.changeColumnName}" label="<#if column.remark != ''>${column.remark}<#else>${column.changeColumnName}</#if>" >
                  <template slot-scope="{ row }">
                    <el-image
                      :src="row.${column.changeColumnName}"
                      :preview-src-list="[row.${column.changeColumnName}]"
                      fit="contain"
                      lazy
                      class="el-avatar"
                    >
                      <div slot="error">
                        <i class="el-icon-document" />
                      </div>
                    </el-image>
                  </template>
                </el-table-column>
              <#else>
                <el-table-column prop="${column.changeColumnName}" label="<#if column.remark != ''>${column.remark}<#else>${column.changeColumnName}</#if>" />
              </#if>
            </#if>
          </#list>
        </#if>
        <el-table-column v-if="checkPer(['admin','${changeClassName}:edit','${changeClassName}:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crud${className }, { defaultForm } from '@/api/hqmes/${changeClassName}/${changeClassName}'
import CRUD, {  createCurd_Hook_BeforeCreated,  presenter, header } from '@crud_my/crud'
import rrOperation from '@crud_my/RR.operation'
import crudOperation from '@crud_my/CRUD.operation'
import udOperation from '@crud_my/UD.operation'
import pagination from '@crud_my/Pagination'
import pictureUpload from '@/components/upload/pictureUpload'
import autocompleteinput from '@/components/inputs/autocomplete-input'


export const bussinessurl =  'api/${changeClassName}'
const components = {
  pagination,
  crudOperation,
  rrOperation,
  udOperation,
  pictureUpload,
  autocompleteinput
}

// 找到components文件夹下以.vue命名的文件
const introductions = require.context('./', true, /\.vue$/) // 返回值是函数
const introductionsLength = introductions.keys() // 返回值是个数组["./A.vue", "./B.vue"]
if (introductionsLength.length) {
  introductionsLength.forEach(fileName => {
    if (fileName === './add_custom.vue') {
      const componentConfig = introductions(fileName) // 动态引入 
      components['addform'] = componentConfig.default || componentConfig // 注册组件
    }
  })
  if (!components['addform']) {
    components['addform'] = () => import('./add')
  }
}

export default {
  name: '${className}',
  components: components,
  mixins: [createCurd_Hook_BeforeCreated(),  presenter(), header()],
  <#if hasDict>
  dicts: [<#if hasDict??><#list dicts as dict>'${dict}'<#if dict_has_next>, </#if></#list></#if>],
  </#if>
  newCrudConfig: {title: '${apiAlias}', url:bussinessurl, idField: '${pkChangeColName}', sort: '${pkChangeColName},desc', crudMethod: { ...crud${className} },defaultForm:defaultForm},
  data() {
    return {
      bussinessurl: bussinessurl,
      permission: {
        add: ['admin', '${changeClassName}:add'],
        edit: ['admin', '${changeClassName}:edit'],
        del: ['admin', '${changeClassName}:del']
      },
	   hiddenColumns: ['createTime', 'createBy', 'updateBy', 'updateTime', 'isDel','id'],
        <#if hasQuery>
            queryTypeOptions: [
                <#if queryColumns??>
                <#list queryColumns as column>
                <#if column.queryType != 'BetWeen'>
                { key: '${column.changeColumnName}', display_name: '<#if column.remark != ''>${column.remark}<#else>${column.changeColumnName}</#if>' }<#if column_has_next>,</#if>
                </#if>
                </#list>
                </#if>
            ],
        </#if>
             dialogWidth: '500px'
    }
  },
  created() {
    //this.crud.props.searchToggle = true
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  },
  computed: {
      isOpenInMain: function () {
        return this.$parent.$vnode.tag.indexOf('AppMain') > 0
      }
  }
}
</script>

<style scoped>

</style>
